package xh.server.processors;

import io.netty.handler.codec.http.FullHttpResponse;
import xh.server.PlayerController;
import xh.server.RequestProcessor;
import xh.server.commands.PlayerCommand;
import xh.server.commands.PlayerOperationFactory;
import xh.server.commands.impl.Play;
import xh.server.commands.impl.Volume;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

/**
 * Created by Administrator on 2016/6/25.
 */
public class PlayerRelateProcessor extends AbstractProcessor {

    private String srcCmd;

    private PlayerCommand playerCommand;

    public PlayerRelateProcessor(String srcCmd) {
        this.srcCmd = srcCmd;
    }

    public void parseCmd() {

        String[] parts = this.srcCmd.split("/");

        playerCommand = PlayerOperationFactory.create(parts[0]);

        if (playerCommand == null) {
            throw new IllegalArgumentException("unknown operation: " + parts[0]);
        }

        playerCommand.initFromParams(Arrays.copyOfRange(parts, 1, parts.length));
    }


    public FullHttpResponse process() {
        playerCommand.doCommand();
        return super.process();
    }
}
